public class lengthOfLongestSubstring {
    public int _lengthOfLongestSubstring(String s) {
        if (s.length() == 0)
            return 0;
        int[] chs = new int[128];
        int left = 0;
        int right = 0;
        int maxLen = 1;
        while (right < s.length()) {
            if (chs[s.charAt(right)] == 0) {
                chs[s.charAt(right)]++;
                maxLen = Math.max(right - left + 1, maxLen);
                right++;
            } else {
                chs[s.charAt(right)]++;
                while (chs[s.charAt(right)] > 1) {
                    chs[s.charAt(left)]--;
                    left++;
                }
                right++;
            }
        }
        return maxLen;
    }
}
